package com.ys.erp.entity.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ys.erp.entity.data.bean.CatExt;
import com.ys.erp.entity.mapper.CatExtMapper;
import com.ys.erp.entity.service.ICatExtService;
import org.springframework.stereotype.Service;


import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author lwj
 * @date 2024/8/15
 */
    
@Service
public class ICatExtServiceImpl extends ServiceImpl<CatExtMapper, CatExt> implements ICatExtService {

    @Override
    public Map<String, CatExt> mapByCatCodes(Collection<String> catCodeList) {
        if (ObjectUtil.isEmpty(catCodeList) || catCodeList.isEmpty()) {
            return new HashMap<>();
        }
        QueryWrapper<CatExt> extQw = new QueryWrapper<>();
        extQw.lambda().in(CatExt::getCatCode, catCodeList);
        return this.list(extQw).stream().collect(Collectors.toMap(CatExt::getCatCode, catExt -> catExt));
    }

    @Override
    public CatExt getByCode(String catCode) {
        QueryWrapper<CatExt> extQw = new QueryWrapper<>();
        extQw.lambda().eq(CatExt::getCatCode, catCode);
        return this.getOne(extQw);
    }

}
